import Vue from 'vue';
import VueRouter from 'vue-router';
import axios from 'axios';
import router from './router';
import App from './App.vue';
import store from './store';
import Home from './components/Home.vue';
import Chat from './components/Chat.vue';
import Loading from './components/loading';
import {isAppIos} from './util/index';

Vue.use(Loading);
Vue.use(VueRouter);

Vue.prototype.$http = axios;


if(isAppIos()){  //手机安卓或者IOS下
    /**2. 模拟器下调试时 **/
    mui.init();
    mui.plusReady(function(){
        //按手机返回键
        var lastTime = Date.now();
        mui.back = function(){
            var now = Date.now();
            if(now - lastTime <500){ //两次时间间隔不超过500毫秒
                plus.runtime.quit();
            }else{
                castapp.prompt('再按一次退出程序');
                lastTime = now;
            }
        }
    });
    window.baseAppAddr; 
    mui.plusReady(function(){
        //平台根地址
        window.baseAppAddr = plus.io.convertLocalFileSystemURL('_www/web/dist');
        //console.log(baseAdrr)
        const router = new VueRouter({
            mode:'history',  //切换路径模式，编程history模式
            //滚动条滚动行为，不加这个默认就会记忆原来滚动条的位置
            routes: [
                {
                    /** 模拟器下真实地址
                     * /storage/emulated/0/Android/data/io.dcloud.HBuilder/apps/HBuilder/www/web/dist/index.html
                     * **/
                    path: baseAppAddr+'/',
                    redirect: baseAppAddr+ '/msg/home'
                },{
                    path: baseAppAddr+'/index.html',
                    redirect: baseAppAddr+'/msg/home'
                },
                {
                    path: baseAppAddr+'/msg/home',
                    component: Home
                },{
                    path: baseAppAddr+'/msg/chat',
                    component: Chat
                },
                {
                    path: baseAppAddr+'/msg/*',
                    redirect: baseAppAddr+'/msg/home'
                }
            ]
        });

        const vm = new Vue({
            el: '#app',
            store,
            router,
            render: h => h(App)
        }).$mount('#app');
        window.vm = vm;
    });
}else{
    //1. 浏览器下
    const vm = new Vue({
        el: '#app',
        store,
        router,
        render: h => h(App)
    }).$mount('#app');
    window.vm = vm;
}

